﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VFCons
{
	public partial class CoordinateControl : UserControl
	{
		public CoordinateControl()
		{
			InitializeComponent();
			tbes.Add(textBoxX1); tbes.Add(textBoxY1); tbes.Add(textBoxU1); tbes.Add(textBoxV1);
			tbes.Add(textBoxX2); tbes.Add(textBoxY2); tbes.Add(textBoxU2); tbes.Add(textBoxV2);
			tbes.Add(textBoxX3); tbes.Add(textBoxY3); tbes.Add(textBoxU3); tbes.Add(textBoxV3);
			tbes.Add(textBoxX4); tbes.Add(textBoxY4); tbes.Add(textBoxU4); tbes.Add(textBoxV4);
			textBoxX1.Tag = "F2"; textBoxY1.Tag = "F2"; textBoxU1.Tag = "F0"; textBoxV1.Tag = "F0";
			textBoxX2.Tag = "F2"; textBoxY2.Tag = "F2"; textBoxU2.Tag = "F0"; textBoxV2.Tag = "F0";
			textBoxX3.Tag = "F2"; textBoxY3.Tag = "F2"; textBoxU3.Tag = "F0"; textBoxV3.Tag = "F0";
			textBoxX4.Tag = "F2"; textBoxY4.Tag = "F2"; textBoxU4.Tag = "F0"; textBoxV4.Tag = "F0";
		}

		List<TextBox> tbes = new List<TextBox>();

		public void Data2UI(List<float> list)
		{
			try
			{
				for (int i = 0; i < list.Count && i < tbes.Count; i++)
				{
					tbes[i].Text = list[i].ToString((string)tbes[i].Tag);
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "ERROR");
			}
		}

		public bool UI2Data(List<float> calib_xyuv)
		{
			try
			{
				foreach (var btn in tbes)
				{
					float fv = Convert.ToSingle(btn.Text);
					calib_xyuv.Add(fv);
				}

				return true;
			}
			catch(Exception ex)
			{
				MessageBox.Show(this, "Coordinate.UI2Data" + Environment.NewLine + ex.Message, "ERROR");
				return false;
			}
		}
	}
}
